var __extends =
    (this && this.__extends) ||
    (function () {
      var t = function (a, i) {
        return (t =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (t, a) {
              t.__proto__ = a;
            }) ||
          function (t, a) {
            for (var i in a)
              Object.prototype.hasOwnProperty.call(a, i) && (t[i] = a[i]);
          })(a, i);
      };
      return function (a, i) {
        function e() {
          this.constructor = a;
        }
        if ("function" != typeof i && null !== i)
          throw new TypeError(
            "Class extends value " + String(i) + " is not a constructor or null"
          );
        t(a, i),
          (a.prototype =
            null === i
              ? Object.create(i)
              : ((e.prototype = i.prototype), new e()));
      };
    })(),
  GangWarsHomeView = (function (t) {
    function a() {
      var a = t.call(this) || this;
      return (
        (a.listArr = []),
        (a.curzjNum = 0),
        a.btn_gangWars_back.on(Laya.Event.CLICK, a, a.onGangWarsDataBack),
        a.btn_wars_GZSM.on(Laya.Event.CLICK, a, a.onDidClickGZAction),
        a.btn_wars_JLSM.on(Laya.Event.CLICK, a, a.onDidClickGZAction),
        a.tab_gangwars_noStart.on(Laya.Event.CLICK, a, a.onTabGangWarsAction),
        a.label_gangwars_up.on(Laya.Event.CLICK, a, a.onDidClickChangeDay),
        a.label_gangwars_down.on(Laya.Event.CLICK, a, a.onDidClickChangeDay),
        a.btn_weibangpaizuozhan.on(
          Laya.Event.CLICK,
          a,
          a.onDidClickBangPaiZuoZhanAction
        ),
        (a.list_gangwars_zhanji.vScrollBarSkin = ""),
        (a.list_gangwars_zhanji.selectEnable = !0),
        (a.list_gangwars_zhanji.renderHandler = new Handler(
          a,
          a.onupdateGangWarsItemFn
        )),
        a.list_gangwars_zhanji.on(
          Laya.Event.CLICK,
          a,
          a.onDidClickListGangWarsAction
        ),
        WebSocketService.addListener({
          caller: a,
          code: 1522,
          method: a.onLoadGangWarsHomeDataFn,
        }),
        WebSocketService.addListener({
          caller: a,
          code: 1526,
          method: a.onLoadGangWarsRuWeiDataFn,
        }),
        WebSocketService.addListener({
          caller: a,
          code: 1530,
          method: a.onLoadGangWarsZhanJiDataFn,
        }),
        WebSocketService.addListener({
          caller: a,
          code: 1531,
          method: a.onLoadGangWarsPrepareDataFn,
        }),
        a
      );
    }
    return (
      __extends(a, t),
      (a.showGangWarsHomeView = function () {
        return (
          null == this.gangwarsV && (this.gangwarsV = new a()),
          WebSocketService.send({ c: 1522 }),
          (this.gangwarsV.tab_gangwars_noStart.selectedIndex = 0),
          (this.gangwarsV.warsState = !1),
          this.gangwarsV
        );
      }),
      (a.prototype.onLoadGangWarsHomeDataFn = function (t) {
        0 == t.code &&
          ("0" == t.data.s
            ? ((this.warsState = !1),
              (this.warsId = t.data.id),
              (this.curzjNum = t.data.id),
              (this.label_gangwars_down.visible = !1),
              (this.timeDiff = t.data.t),
              (this.label_gangwars_timecountdown.text = Utils.timeCountDown(
                this.timeDiff
              )),
              Laya.timer.loop(1e3, this, this.timerCountDownMatchFn),
              WebSocketService.send({ c: 1530, d: { i: t.data.id } }),
              (this.label_wars_listTitle.text =
                "第 " + t.data.id + " 届晋级赛排名"),
              (this.btn_weibangpaizuozhan.visible = !1),
              (this.label_gangwars_up.visible = !0),
              (this.tab_gangwars_noStart.visible = !0),
              (this.label_gangwars_curPerson.text = ""))
            : ((this.warsState = !0),
              (this.warsId = t.data.id),
              (this.label_julibisaihaiyou.text = ""),
              (this.timeDiff = t.data.t),
              (this.label_gangwars_timecountdown.text =
                Utils.timeCountDown(this.timeDiff) + "后比赛结束"),
              (this.label_gangwars_timecountdown.x = 58),
              Laya.timer.loop(1e3, this, this.timerCountDownMatchFn),
              (this.label_gangwars_curPerson.text =
                "当前晋级赛人数：" + t.data.c + "人"),
              (this.btn_weibangpaizuozhan.visible = !0),
              (this.label_gangwars_up.visible = !1),
              (this.label_gangwars_down.visible = !1),
              (this.tab_gangwars_noStart.visible = !1),
              WebSocketService.send({ c: 1530, d: { i: t.data.id } })));
      }),
      (a.prototype.onLoadGangWarsRuWeiDataFn = function (t) {
        if (0 == t.code) {
          this.listArr = [];
          var a = void 0;
          if (this.currentPage >= 1) {
            if (0 == t.list.length) return void this.currentPage--;
            for (var i = 0; i < t.data.length; i++) {
              var e = t.list[i];
              this.listArr.push(e), (this.dataSource = []);
            }
          } else (this.listArr = t.data), (this.dataSource = []);
          (this.isloading = !1), (this.list_gangwars_zhanji.visible = !0);
          for (var n = 0; n < this.listArr.length; n++) {
            var s = this.listArr[n];
            (a = {
              label_war_index: { text: this.dealFingureIndex(s.i) },
              label_wars_name: { text: "" },
              label_wars_jifen: { text: s.n },
            }),
              this.dataSource.push(a);
          }
          this.list_gangwars_zhanji.dataSource = this.dataSource;
        }
      }),
      (a.prototype.onLoadGangWarsZhanJiDataFn = function (t) {
        if (0 == t.code) {
          this.listArr = [];
          var a = void 0;
          if (this.currentPage >= 1) {
            if (0 == t.list.length) return void this.currentPage--;
            for (var i = 0; i < t.data.length; i++) {
              var e = t.data[i];
              this.listArr.push(e), (this.dataSource = []);
            }
          } else (this.listArr = t.data), (this.dataSource = []);
          (this.isloading = !1), (this.list_gangwars_zhanji.visible = !0);
          for (var n = 0; n < this.listArr.length; n++) {
            var s = this.listArr[n];
            (a = {
              label_war_index: { text: this.dealFingureIndex(n + 1 + "") },
              label_wars_name: { text: s.n + " (获胜 " + s.c + " 次)" },
              label_wars_jifen: { text: "" },
            }),
              this.dataSource.push(a);
          }
          this.list_gangwars_zhanji.dataSource = this.dataSource;
        }
      }),
      (a.prototype.onupdateGangWarsItemFn = function (t, a) {
        if (!(a > this.listArr.length)) {
          var i = t.getChildByName("label_war_index");
          i.color =
            0 == a
              ? "#FFFF00"
              : 1 == a
              ? "#c0c0c0"
              : 2 == a
              ? "#CDAF95"
              : "#FFFFFF";
        }
      }),
      (a.prototype.timerCountDownMatchFn = function () {
        this.timeDiff--,
          this.timeDiff >= 0
            ? 1 == this.warsState
              ? (this.label_gangwars_timecountdown.text =
                  Utils.timeCountDown(this.timeDiff) + "后比赛结束")
              : (this.label_gangwars_timecountdown.text = Utils.timeCountDown(
                  this.timeDiff
                ))
            : this.timeDiff % 15 == 0
            ? 1 == this.warsState && WebSocketService.send({ c: 1522 })
            : (Laya.timer.clear(this, this.timerCountDownMatchFn),
              (this.label_gangwars_timecountdown.text = "请稍等..."),
              WebSocketService.send({ c: 1522 }));
      }),
      (a.prototype.onTabGangWarsAction = function (t) {
        0 == this.warsState &&
          ("item0" == t.target.name
            ? (this.curzjNum <= 1
                ? ((this.label_gangwars_up.visible = !1),
                  (this.label_gangwars_down.visible = !0))
                : this.curzjNum == parseInt(this.warsId) &&
                  ((this.label_gangwars_up.visible = !0),
                  (this.label_gangwars_down.visible = !1)),
              WebSocketService.send({ c: 1530, d: { i: this.warsId } }),
              (this.label_wars_listTitle.text =
                "第 " + this.curzjNum + " 届晋级赛排名"))
            : "item1" == t.target.name &&
              (WebSocketService.send({ c: 1526 }),
              (this.label_gangwars_down.visible = !1),
              (this.label_gangwars_up.visible = !1),
              (this.label_wars_listTitle.text = "入围决战帮派的排名")));
      }),
      (a.prototype.onDidClickGZAction = function (t) {
        if ("item0" == t.target.name) {
          ((a = RulesView.showCaslRuleView("gangWarsGZSM")).y = 0),
            Laya.stage.addChild(a);
        } else {
          var a = RulesView.showCaslRuleView("gangWarsJLSM");
          (a.y = 0), Laya.stage.addChild(a);
        }
      }),
      (a.prototype.dealFingureIndex = function (t) {
        var a = "";
        return (
          1 == this.tab_gangwars_noStart.selectedIndex && (a = "上届"),
          "1" == t
            ? a + "冠军"
            : "2" == t
            ? a + "亚军"
            : "3" == t
            ? a + "季军"
            : t
        );
      }),
      (a.prototype.onDidClickListGangWarsAction = function (t) {
        if ("" != t.target.name) {
          var a = this.listArr[this.list_gangwars_zhanji.selectedIndex],
            i = {
              type: "jinjisai",
              title: a.n,
              bangpaiId: a.id,
              zgs_id: this.warsId,
            },
            e = GangWarsManagerView.showGangWarsMgrView(i);
          Laya.stage.addChild(e);
        }
      }),
      (a.prototype.onDidClickChangeDay = function (t) {
        "下一届" == t.target.text
          ? ((this.label_gangwars_up.visible = !0),
            this.curzjNum++,
            this.curzjNum > parseInt(this.warsId)
              ? (this.curzjNum -= 1)
              : this.curzjNum == parseInt(this.warsId) &&
                (this.label_gangwars_down.visible = !1))
          : ((this.label_gangwars_down.visible = !0),
            this.curzjNum--,
            this.curzjNum <= 1 &&
              ((this.curzjNum = 1), (this.label_gangwars_up.visible = !1))),
          (this.label_wars_listTitle.text =
            "第 " + this.curzjNum + " 届晋级赛排名"),
          WebSocketService.send({ c: 1530, d: { i: this.curzjNum } });
      }),
      (a.prototype.onDidClickBangPaiZuoZhanAction = function () {
        WebSocketService.send({ c: 1531 });
      }),
      (a.prototype.onPiPeiDuiShouFunction = function () {
        WebSocketService.send({ c: 1531 });
      }),
      (a.prototype.onQuitMatchFunction = function () {
        WebSocketService.send({ c: 1527 });
      }),
      (a.prototype.onLoadGangWarsPrepareDataFn = function (t) {
        0 == t.code
          ? MatchOtherDialog.showMatchNormalDialog(
              "正在匹配...",
              this,
              this.onPiPeiDuiShouFunction,
              this.onQuitMatchFunction
            )
          : Alert.openText(t.msg);
      }),
      (a.prototype.onGangWarsDataBack = function () {
        Laya.timer.clear(this, this.timerCountDownMatchFn),
          Laya.timer.clearAll(this),
          this.removeSelf();
      }),
      a
    );
  })(ui.ChallengeBattle.GangWarsHomeViewUI);
